package day06;

import org.apache.flink.runtime.state.filesystem.FsStateBackend;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.KeyedProcessFunction;
import org.apache.flink.util.Collector;
import untils.ClickEvent;
import untils.ClickSource;

/**
 * 检查点
 */
public class Example1 {
    public static void main(String[]args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        //设置每隔十秒保存检查点
        env.enableCheckpointing(10 * 1000L);
        //添加保存路径
        env.setStateBackend(new FsStateBackend("D:\\atguigu\\flinkdata\\src\\main\\resources"));

        env
                .addSource(new ClickSource())
                .keyBy(r -> r.username)
                .process(new KeyedProcessFunction<String, ClickEvent, ClickEvent>() {
                    @Override
                    public void processElement(ClickEvent value, Context ctx, Collector<ClickEvent> out) throws Exception {
                        out.collect(value);
                    }
                })
                .print();

        env.execute();

    }
}
